import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:xuance/RoutePath.dart';
import 'package:xuance/bean/exp.dart';
import 'package:xuance/network/api/UserApi.dart';
import 'package:xuance/util/toast_util.dart';

class LoginLogic extends GetxController {
  var account = "admin".obs;
  var password = "Ama12345".obs;

  var check = false.obs;

  @override
  void onInit() {
    super.onInit();
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
  }

  Future<void> login() async {
    if (!check.value) {
      showToast("请阅读并同意《隐私政策》和《服务条款》");
      return;
    }
    if (account.isEmpty) {
      showToast("请输入账号");
      return;
    }
    if (password.isEmpty) {
      showToast("请输入密码");
      return;
    }
    try {
      await UserApi.login(account: account.value, password: password.value);
      Get.offAllNamed(RoutePath.home);
    } catch (e) {
      if (e is ApiException) {
        showToast(e.message);
      } else {
        showToast("$e");
      }
    }
  }
}
